package com.hyyt.shopjsp.store.info.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import com.hyyt.shopjsp.product.pojo.ShopShopProCategory;
import com.hyyt.shopjsp.product.service.IShopShopProCategoryService;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.hyyt.shopjsp.common.controller.BaseController;
import com.hyyt.shopjsp.product.service.IShopProductInfoService;
import com.hyyt.shopjsp.util.common.Page;
import com.hyyt.shopjsp.util.common.ResultMsg;

/**
 * Copyright (c) 2017 ShopJsp. All Rights Reserved.
 * ============================================================================
 * 版权所有 2011 - 今 北京华宇盈通科技有限公司，并保留所有权利。
 * ----------------------------------------------------------------------------
 * 提示：在未取得SHOPJSP商业授权之前，您不能将本软件应用于商业用途，否则SHOPJSP将保留追究的权力。
 * ----------------------------------------------------------------------------
 * 官方网站：http://www.shopjsp.com
 * ============================================================================
 * @author Wang Youchun on 2017/04/24 0024上午 10:46.
 */

@Controller
@RequestMapping("/back/shopProCategory")
public class ShopShopProCategoryController extends BaseController{
	
	private Logger log = Logger.getLogger(ShopShopProCategoryController.class);
	private String basePath = "/back/shop/shopProCategory/";
	@Resource
	private IShopProductInfoService shopProductInfoService;//商品service
	@Resource
	private IShopShopProCategoryService shopShopProCategoryService;//店铺商品内部分类service
	/**
	 * 根据店铺ID跳转到店铺商品列表页
	 * @param shopInfoId 店铺id
	 * @param param
	 * @return
	 */
	@RequestMapping("gotoShopProCategory")
	public String gotoShopProCategory(String shopInfoId, Map<String, Object> param){
		param.put("shopInfoId", shopInfoId);
		return basePath+"ruZhuShopProCategoryList";
	}

	/**
	 * 根据店铺ID查询该店铺的商品
	 * @param page
	 * @param response
	 */
	@RequestMapping("findProductListByShopInfoId")
	@ResponseBody
	public void findProductListByShopInfoId(String shopInfoId,Page page, HttpServletResponse response){
		Map<String, Object> param = new HashMap<>();
		param.put("shopInfoId", shopInfoId);
		param.put("sortColumns", "productId desc");
		int totalRecordCount =shopProductInfoService.countShopProductInfo(param);
		page.setPageInfo(page.getPageSize(), totalRecordCount, page.getCurrentPage());
		List<Map<String,Object>> productInfoList =shopProductInfoService.queryShopProductInfo(param, page.getPageRecordBeginIndex(), page.getPageSize());
		param.clear();
		param.put("total", totalRecordCount);// total键 存放总记录数，必须的
		param.put("rows", productInfoList);// rows键 存放每页记录 list
		ResultMsg.create(param, response);  //把内容发送到页面
	}

	/**
	 * 根据店铺ID查询该店铺的店铺商品内部分类
	 * @param shopInfoId 店铺Id
	 * @param response
	 */
	@RequestMapping("getShopProCategoryByShopInfoId")
	@ResponseBody
	public void getShopProCategoryByShopInfoId(String shopInfoId,HttpServletResponse response){
		Map<String, Object> param = new HashMap<>();
		param.put("shopInfoId", shopInfoId);
		param.put("sortColumns", "sortCode desc");
		List<ShopShopProCategory> shopProCategoryList =shopShopProCategoryService.queryShopShopProCategory(param);
		param.clear();
		param.put("shopProCategoryList", shopProCategoryList);// rows键 存放每页记录 list
		ResultMsg.create(param, response);  //把内容发送到页面
	}

}
